/**
 * SSD1306/SH1106 OLED Display Driver
 */

#ifndef __SSD1306_H__
#define __SSD1306_H__

#include "main.h"
#include "i2c.h"

// 选择控制器: 0=SSD1306, 1=SH1106
#ifndef SSD1306_CONTROLLER_SH1106
#define SSD1306_CONTROLLER_SH1106 0
#endif

// SH1106调试模式
#define SH1106_DEBUG_MODE 1

// SSD1306 I2C地址 (7-bit)
#define SSD1306_I2C_ADDR        0x3C

// 显示宽度和高度
#define SSD1306_WIDTH           128
#define SSD1306_HEIGHT          64

// SSD1306命令集
#define SSD1306_COMMAND         0x00
#define SSD1306_DATA            0x40

// 控制命令
#define SSD1306_SETCONTRAST     0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON    0xA5
#define SSD1306_NORMALDISPLAY   0xA6
#define SSD1306_INVERTDISPLAY   0xA7
#define SSD1306_DISPLAYOFF      0xAE
#define SSD1306_DISPLAYON       0xAF

// 滚动命令
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
#define SSD1306_DEACTIVATE_SCROLL 0x2E
#define SSD1306_ACTIVATE_SCROLL 0x2F

// 地址设置命令
#define SSD1306_SETLOWCOLUMN    0x00
#define SSD1306_SETHIGHCOLUMN   0x10
#define SSD1306_MEMORYMODE      0x20
#define SSD1306_COLUMNADDR      0x21
#define SSD1306_PAGEADDR        0x22
#define SSD1306_COMSCANINC      0xC0
#define SSD1306_COMSCANDEC      0xC8
#define SSD1306_SEGREMAP        0xA0
#define SSD1306_CHARGEPUMP      0x8D
#define SSD1306_EXTERNALVCC     0x01
#define SSD1306_SWITCHCAPVCC    0x02

// 显示缓冲区大小
#define SSD1306_BUFFER_SIZE     (SSD1306_WIDTH * SSD1306_HEIGHT / 8)

// 函数声明
uint8_t SSD1306_Init(I2C_HandleTypeDef *hi2c);
uint8_t SSD1306_TestConnection(void);
void SSD1306_DisplayOn(void);
void SSD1306_DisplayOff(void);
void SSD1306_Clear(void);
void SSD1306_UpdateScreen(void);
void SSD1306_DrawPixel(uint8_t x, uint8_t y, uint8_t color);
void SSD1306_Fill(uint8_t color);
void SSD1306_WriteChar(char ch, uint8_t fontWidth, uint8_t fontHeight);
void SSD1306_WriteString(char* str, uint8_t fontWidth, uint8_t fontHeight);
void SSD1306_SetCursor(uint8_t x, uint8_t y);
void SSD1306_InvertDisplay(void);
void SSD1306_NormalDisplay(void);
void SSD1306_AllOn(void);

void SSD1306_ShowCustomChar(uint8_t x, uint8_t y, const uint8_t *charData, uint8_t clearScreen);
void SSD1306_DrawHeart(uint8_t x0, uint8_t y0, uint8_t scale);
void SSD1306_DrawStandardHeart(uint8_t x0, uint8_t y0, uint8_t radius);
void SSD1306_HeartBeatAnimation(uint8_t x0, uint8_t y0, uint8_t radius, uint16_t stepDelay);
void SSD1306_ShowChinese16x16(uint8_t x, uint8_t y, const uint8_t *hanzi, uint8_t clear);
void SSD1306_ShowChinese16x16_Rotate(uint8_t x, uint8_t y, const uint8_t *hanzi,
                                     uint8_t rotate, uint8_t clear);
void SSD1306_HorizontalScroll(uint8_t dir, uint8_t start_page, uint8_t end_page, uint8_t interval);




#endif /* __SSD1306_H__ */